Miniconda Installation

Install Miniconda from their Website. All required python packages will be downloaded using the conda package and environment management system. When Miniconda is installed on your system, open up your shell with the command WINDOWS + R -> cmd on windows or search for the terminal on Linux systems.

Then type this to make sure you got the latest version.


In [ ]:
conda update --all

A new environment capsule with preset libraries installed for one or more of your projects can be created. fauenv is the name of the new python 3.x environment in this example.


In [ ]:
conda create -n fauenv python=3

Check which environments are currently installed. root is the name of the default one.


In [ ]:
conda info -e

Then, activate the desired environment.


In [ ]:
activate fauenv

Install Packages for Machine Learning / Pattern Recognition

With this command, all required packages as well as their dependencies will be installed in the latest version possible. Version conflicts between them are avoided automatically.

Note, those packages are only installed for the chosen environment. If you want to install them on another environment in the same version,conda automatically creates the hardlinks to the library's directory, avoiding to have numerous copies of the same library on the filesystem.

Install

Use conda to install new packages.


In [ ]:
conda install -n fauenv numpy scipy matplotlib scikit-learn scikit-image ipython ipython-notebook  
conda install -n fauenv nose pip anaconda-client pillow ujson flask jinja2 natsort joblib numba pyside

Install packages not in the conda repository via pip.


In [ ]:
activate fauenv # if not in fauenv environment already
pip install visvis tinydb nibabel pydicom medpy simpleITK pycuda numpy-stl websockets

Clean up

In order to free about 330MB of disc space after installation, delete the cached tar.bz archive files. Packages no longer needed as dependencies can be deleted as well.


In [ ]:
conda clean -tps # delete downloaded cached tarballs (t), orphaned packages (p), and cached sources (s)

Update

To update all packages of a specific environment call


In [ ]:
conda update --all -n fauenv
activate fauenv # if not in fauenv environment already
pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip install -U

Now, all is set up to get started.

Using Jupyter Notebook

The Jupyter Notebook is a web-based interactive computational environment to combine code execution, text, mathematics, plots and rich media into a single document.

Jupyter stands for Julia, Python and R, which are the main proramming languages supported.

There are several tutorials for this framework.

To start Jupyter Notebook call


In [ ]:
jupyter notebook # --port 8888

The console will show an URL like http://localhost:8888/tree and open the operating system's default browser with this location. Use it to navigate, open, create, delete, and run .ipynb files.

Note: For inline plots use this magic function at the beginning of your code. This also imports numpy as np, imports matplotlib.pyplot as plt, and others.


In [ ]:
%pylab inline

Jupyter Notebook magic functions

Unlike traditional python, the Jupyter notebook offers some extended timing, profiling, aliasing and other functionalities via it's magic functions.

An example:


In [1]:
%time sum(range(int(1e7)))


Wall time: 343 ms
Out[1]:
49999995000000

In [2]:
%timeit sum(range(10000000))


1 loop, best of 3: 357 ms per loop

In standard python this would be achieved by


In [ ]:
python -mtimeit -s"import test" "mytestFunction(42)"

Some useful magic functions are

  • %time or %timeit for benchmarks
  • %prun for profiling
  • %magic returns a list of all magic functions
  • %load or %loadpy to import a .py file into the notebook
  • %quickref for a reference sheet

In [ ]:
%quickref

Further readings

There are some great websites where ready-made Jupyter Notebook files can be found and imported:

  1. Nbviewer: An online .ipynb render engine for notebooks on github
    1. Jupyter Notebook Tutorial
    2. Good Scikit-learn Tutorial
  2. Google: segmentation type:ipynb github

Day two

When you come back to working with scikit-learn and jupyter notebook, use those commands to get the fresh releases and start the server


In [ ]:
conda update --all
conda update --all -n fauenv
activate fauenv
conda clean -tps
pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip install -U
jupyter notebook

Upgrading to a new version of python


In [ ]:
activate fauenv
conda install python=3.6

Environment Integration into an IDE

PyCharm

Download the IDE here: jetbrains.com

In PyCharm go to

  1. File → Settings, or use Strg + Alt + S
  2. Project Interpreter → <project name> → gear symbol → Add Local
  3. Navigate to some path like C:\Miniconda3\envs\fauenv\python.exe, where fauenv is the environment you want to use